﻿using System.ComponentModel;
using System.Reflection;


namespace AiMachineControl.Model
{
    public class EnumModel
    {
        /// <summary>
        /// 获取枚举描述
        /// </summary>
        /// <param name="enumValue">枚举值</param>
        /// <returns></returns>
        public string GetEnumDescription(Enum enumValue)
        {
            string value = enumValue.ToString();
            FieldInfo field = enumValue.GetType().GetField(value);
            object[] objs = field.GetCustomAttributes(typeof(DescriptionAttribute), false); //获取描述属性
            if (objs == null || objs.Length == 0) //当描述属性没有时，直接返回名称
                return value;
            DescriptionAttribute descriptionAttribute = (DescriptionAttribute)objs[0];
            return descriptionAttribute.Description;
        }

        /// <summary>
        /// 得到enum字段描述列表
        /// </summary>
        /// <returns>返回字典</returns>
        public static Dictionary<string, string> EnumFieldDescription(Type enumType)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            Type type = typeof(DescriptionAttribute);
            FieldInfo[] fields = enumType.GetFields();
            foreach (FieldInfo field in fields)
            {
                object[] arr = field.GetCustomAttributes(type, true);
                if (arr.Length > 0)
                {
                    dic.Add(field.Name, ((DescriptionAttribute)arr[0]).Description);
                }
            }
            return dic;
        }

        /// <summary>
        /// AI模型类型枚举
        /// </summary>
        public enum MachineTypeEnum
        {
            [Description("换声音")]
            AiVoice = 0,
            [Description("AI换脸")]
            AiFace = 1,
            [Description("数字人")]
            AiPerson = 2,
            [Description("大语言")]
            ChatGpt = 3
        }

        /// <summary>
        /// 算力机状态枚举
        /// </summary>
        public enum MachineStatusEnum
        {
            [Description("准备")]
            Reading = 88,
            [Description("结束")]
            Ending = 44,
            [Description("指定项目更新")]
            Updating = 77,
            [Description("心跳包通知")]
            HertNotice = 99,
            [Description("音频拆包")]
            SplitVoice = 33,
            [Description("视频合成")]
            VideoCombine = 22
        }
        /// <summary>
        /// 动作枚举
        /// </summary>
        public enum ActionTypeEnum
        {
            [Description("项目启动")]
            MachineStart = 200,
            [Description("项目关闭")]
            MachineClose = 500,
            [Description("算力机维护")]
            MachineRepair = 301,
            [Description("算力机维护结束")]
            MachineRepairEnd = 302,
            [Description("算力机异常")]
            MachineError = 404,
            [Description("心跳包通知")]
            HertNotice = 99,
            [Description("音频拆包完成")]
            SplitEnd = 333,
            [Description("视频推理完成")]
            OfflinFinish = 444,
            [Description("视频合成完成")]
            VideoCombine = 222
        }
    }
}
